﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.IO;
using System.Text.RegularExpressions;

namespace ECSS.Winform
{
    public partial class FrmAnalysisCancelOrderLog : Form
    {
        public FrmAnalysisCancelOrderLog()
        {
            InitializeComponent();
        }

        private void btnAnalysis_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("日志存放目录:'{0}'\r\n", ConfigurationManager.AppSettings["cancelBossOrderLogDir"]));

            DirectoryInfo di = new DirectoryInfo(ConfigurationManager.AppSettings["cancelBossOrderLogDir"]);
            sb.Append(string.Format("目录下的日志文件共:{0}个\r\n", di.GetFiles("*.txt").Length));

            int i = 0;

            foreach (FileInfo fi in di.GetFiles("*.txt"))
            {
                //sb.Append(string.Format("分析[{0}]......\r\n", fi.Name));

                using (StreamReader sr = fi.OpenText())
                {
                    string filecontent = sr.ReadToEnd();

                    foreach (string block in Regex.Split(filecontent, "End;================================================", RegexOptions.IgnoreCase))
                    {
                        if (block.Contains("<Succeed>false</Succeed>"))
                        {
                            foreach (string s in Regex.Split(block,"\r",RegexOptions.IgnoreCase))
                            {
                                if (s.Contains("2010"))
                                {
                                    sb.Append(string.Format("{0},", s));
                                }
                                
                                if (s.Contains("BOSSOrderID"))
                                {
                                    sb.Append(string.Format("{0}\r\n", (s.Replace("BOSSOrderID:", string.Empty)).Replace("\n",string.Empty)));
                                    i++;
                                }
                            }                            
                        }
                    }          
                }
            }

            sb.Append(string.Format("取消预订单失败共{0}单", i));

            textBox1.Text = sb.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(textBox1.Text);
        }


    }
}
